﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using DragDraw.Util;

namespace DragDraw.Tool
{
    public partial class PhotoGrid : UserControl
    {
        private bool m_isShow = false;
        public PhotoGrid()
        {
            InitializeComponent();
            Visibility = Visibility.Collapsed;
            AnimHide.Completed += new EventHandler(delegate(object sender, EventArgs e)
            { this.Visibility = Visibility.Collapsed; });
        }

        private string m_imageSrc = "";
        private int m_z;

        public string ImageSrc
        {
            get { return m_imageSrc; }
            set
            {
                try
                {
                    string url = value;
                    m_imageSrc = value;
                    if (url.Contains(@"http://") == false)
                        url = WidgetHelper.MapFileUrl(
                            OperationManager.Instance.CurrentSpace.OwnerUserID, url);
                    ImgMain.ImageSource = new BitmapImage(new Uri(url));
                }
                catch
                {
                    ImgMain.ImageSource = new BitmapImage();
                }
            }
        }

        public double PosX
        {
            get { return (double)(GetValue(Canvas.LeftProperty)); }
            set
            {
                SetValue(Canvas.LeftProperty, value);
            }
        }
        public double PosY
        {
            get { return (double)(GetValue(Canvas.TopProperty)); }
            set
            {
                SetValue(Canvas.TopProperty, value);
            }
        }
        /// <summary>
        /// 0到100，越大越前越清晰，简易在70-100
        /// </summary>
        public int PosZ
        {
            get { return m_z; }
            set
            {
                Height = 150 * (PosZ / 100.0);
                Width = 200 * (PosZ / 100.0);
                Opacity = PosZ / 100.0;
                SetValue(Canvas.ZIndexProperty, value);
                m_z = value;
            }
        }

        public bool Show
        {
            get { return m_isShow; }
            set
            {
                if (!m_isShow && value)
                {
                    Visibility = Visibility.Visible;
                    AnimShow.Begin();
                }
                else if (m_isShow && !value)
                {
                    AnimHide.Begin();

                }
                m_isShow = value;
            }
        }
    }
}
